package JLib.component
{
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class Slider extends MovieClip
	{
		protected var slider:Object;
		protected var plusButton:MovieClip;
		protected var minusButton:MovieClip;
		
		public function Slider(): void
		{
		}
		
		public function setPlusButton(plus:MovieClip): void
		{
			plusButton = plus;
			plusButton.addEventListener(MouseEvent.CLICK, plusValue );
		}
		
		public function setMinusButton(minus:MovieClip): void
		{
			minusButton = minus;
			minusButton.addEventListener(MouseEvent.CLICK, minusValue );
		}
		
		public function setSlider(slider:Object): void
		{
			this.slider = slider;
			if(slider.snapInterval == 0) slider.snapInterval = 1/(Math.abs(slider.minimum)+Math.abs(slider.maximum));
			slider.addEventListener(Event.CHANGE, this.dispatchEvent );
		}
		
		private function plusValue(e:Event): void 
		{ 
			slider.value += slider.snapInterval;
			this.dispatchEvent(new Event(Event.CHANGE));
		}
		
		private function minusValue(e:Event): void
		{ 
			slider.value -= slider.snapInterval; 
			this.dispatchEvent(new Event(Event.CHANGE));
		}
		
		public function get value(): Number { return slider.value; }
		public function get snapInterval(): Number { return slider.snapInterval; }
		public function set snapInterval(value:Number): void { slider.snapInterval = value; }
		public function set value(value:Number): void { slider.value = value; }
		public function get maximum(): Number { return slider.maximum }
		public function set maximum(value:Number): void { slider.maximum = value; }
		public function get minimum(): Number { return slider.minimum }
		public function set minimum(value:Number): void { slider.minimum = value; } 
		
	}//c
}